﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommHelper;
using CommData;

namespace SocketSvrBiz
{
    public class UserToken
    {
        public SendResponse sendResponse = null;
        public SendResponse sendResponseAll = null;
        public int userJobnum = 0;
        public uint Ipaddress = 0;
    }

    partial class BaseBiz
    {
        public UserToken userToken
        {
            get;
            set;
        }

        private SendResponse sendResponse
        {
            get
            {
                return userToken.sendResponse;
            }
        }

        private SendResponse sendResponseAll
        {
            get
            {
                return userToken.sendResponseAll;
            }
        }

        private int jobnum
        {
            get
            {
                return userToken.userJobnum;
            }
            set
            {
                userToken.userJobnum = value;
            }
        }

        private uint Ipaddress
        {
            get
            {
                return userToken.Ipaddress;
            }
        }

        /// <summary>
        /// 从字典中获取字符串
        /// </summary>
        /// <param name="r"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        private string TryGetString(Dictionary<string, object> r, string key)
        {
            string v = null;

            try
            {
                v = Convert.ToString(r[key]);
            }
            catch (Exception)
            {
                v = null;
            }

            return v;
        }

        /// <summary>
        /// 从字典中获取整数
        /// </summary>
        /// <param name="r"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        private int? TryGetInt(Dictionary<string, object> r, string key)
        {
            int? v = null;

            try
            {
                v = Convert.ToInt32(r[key]);
            }
            catch (Exception)
            {
                v = null;
            }

            return v;
        }

        /// <summary>
        /// 从字典中获取小数
        /// </summary>
        /// <param name="r"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        private decimal? TryGetDecimal(Dictionary<string, object> r, string key)
        {
            decimal? v = null;

            try
            {
                v = Convert.ToDecimal(r[key]);
            }
            catch (Exception)
            {
                v = null;
            }

            return v;
        }

        /// <summary>
        /// 从字典获取datetime
        /// </summary>
        /// <param name="r"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        private DateTime? TryGetDateTime(Dictionary<string, object> r, string key)
        {
            DateTime? v = null;

            try
            {
                v = Convert.ToDateTime(r[key]);
            }
            catch (Exception)
            {
                v = null;
            }

            return v;
        }

        protected readonly Domain.Operation.IOperationServices _OperationServices = new Domain.Operation.OperationServices();
    }
}